package cn.kgc.dao.impl;

import cn.kgc.dao.AccountDao;
import cn.kgc.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.util.List;

public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {

    public Account getAccountByNum(String accountNum) {
        List<Account> accountList= getJdbcTemplate().query("select * from account where accountNum=?",new BeanPropertyRowMapper<Account>(Account.class),accountNum);
        if (accountList.size()==0){
            return null;
        }else{
            return accountList.get(0);
        }
    }

    public Integer updateAccount(Account account) {
        return getJdbcTemplate().update("update account set accountMoney=? where accountNum=?",account.getAccountMoney(),account.getAccountNum());
    }
}
